class ArticlesController < ApplicationController
  load_and_authorize_resource
  
  def index
    @articles = Article.paginate(:per_page => 3, :page => params[:page], :order => 'created_at DESC').reverse

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @articles }
      format.json { render :json => @articles }
      format.atom # index.atom.builder	me permet d'avoir atom
      format.js   # index.js.rjs			me permet d'avoir la pagination
    end
  end
  
  def show
    @comment = Comment.new(:article => @article)
  end
  
  def new
  end
  
  def create
    @article.user = current_user
    if @article.save
      flash[:notice] = "Successfully created article."
      redirect_to @article
    else
      render :action => 'new'
    end
  end
  
  def edit
  end
  
  def update
    if @article.update_attributes(params[:article])
      flash[:notice] = "Successfully updated article."
      redirect_to @article
    else
      render :action => 'edit'
    end
  end
  
  def destroy
    @article.destroy
    flash[:notice] = "Successfully destroyed article."
    redirect_to articles_url
  end
end